package demo;

import com.lm.mapper.clazzMapper;
import com.lm.mapper.companyMapper;
import com.lm.mapper.studentMapper;
import com.lm.pojo.Clazz;
import com.lm.pojo.Company;
import com.lm.pojo.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Auther: Min.Liu
 * @Description:
 * @Date: Created in 9:39 2025/3/25
 */
public class Demo1 {
    private SqlSession sqlSession;

    @Before
    public void before() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession = sqlSessionFactory.openSession(true);
    }

    @Test
    public void testselect() {
        companyMapper mapper = sqlSession.getMapper(companyMapper.class);
        List<Company> list = mapper.selectAll();
        for (Company company : list) {
            System.out.println(company);
        }
    }

    @Test
    public void insert() {
        companyMapper mapper = sqlSession.getMapper(companyMapper.class);
        Company company = new Company();
        company.setCompanyNo("101011");
        company.setEnableFlag("NO");
        company.setCompanyName("小刘烧烤摊");
        company.setBoss("刘敏");
        company.setAddress("武汉");
        company.setRegisteredFund("200000");
        company.setRegisteredTime(LocalDateTime.now());
        company.setInsuranceNumber(2);
        company.setState("1");
        mapper.insert(company);
        System.out.println(company);
    }

    @Test
    public void testSetTag() {
        companyMapper mapper = sqlSession.getMapper(companyMapper.class);
        Company company = new Company();
        company.setId(2);
        company.setCompanyNo("101011");
        company.setEnableFlag("NO");
        company.setAddress("松滋");
        company.setRegisteredTime(LocalDateTime.now());
        company.setState("1");
        int count = mapper.update(company);
        System.out.println(count);
    }
}
